function CardStore(){}
/**
 * 选择卡片规格
 */
CardStore.selCardSpec = function(handle,options){	
	var url = spellUrl("/store/sel_white_list.html",options)
	openDialogFrame(url,'选择规格',464,700,handle)	
}

/**
 * 选择卡片类型
 */
CardStore.selCardType = function(handle,options){	
	var url = spellUrl("/basic/card_type_list.html",options)
	openDialogFrame(url,'选择卡片类型',464,700,handle)	
}

/**
 * 显示白卡单据
 * @param divId 显示模板的区域id
 * @param id	个人帐户id
 */
CardStore.showBlankBill = function(divId,id,btnFunc){
	if (!id) return;	
	DWR.call("blankCardStoreService.getBill",id,function(result){
		Rpc.loadPage(divId,"/store/blankcard_bill_div.html",function(){
			var bill = result.bill
			if(bill.billType == Constants.CARD_BILL_TYPE_OUT || bill.billType == Constants.CARD_BILL_TYPE_ADJUST){
				$('leftFactoryDate_Label').innerHTML="";
			}
			var status = bill.status;
			bill.operName = result.operName
			bill.amount = Math.abs(bill.amount)
			bill.billType = Common.getText('cardbill_type',bill.billType)
			bill.subType = Common.getText('blankcardbill_subtype',bill.subType)
			bill.cardType = Common.getText('blankcard_type',bill.cardType)
			bill.status = Common.getText('commonbill_status',bill.status)
			bill.recordTime = Format.formatToMM(bill.recordTime);
			bill.cancelOper = result.cancelOper
			bill.cancelTime = Format.formatToMM(result.cancelTime)
			
			Common.showDetail('blankbill_detail_main',bill);
			Common.showDetail('blankbill_detail_spec',result.spec);
			
			if(status==CardBillStatus.COMMON_CANCELED || status==CardBillStatus.COMMON_CANCEL){
				$("relatedId_Label").style.display = "";
			}else{
				$("relatedId_Label").style.display = "none";
			}
			$('blankbill_detail_canceltr').style.display=status==CardBillStatus.COMMON_CANCELED?'':'none'
			if (btnFunc && status!=BlankCardBillStatus.COMMON_CANCEL)
			{
				$('blankbill_detail_buttons').innerHTML = btnFunc(bill)
				$('blankbill_detail_buttons').style.display=''
			}
			else{
				$('blankbill_detail_buttons').style.display='none'
			}

			switchPage(divId);			
		});
	},{blockScreen:true});
}

function getBillParams(cardBill){
	var params = {}
	params.id = cardBill.id
	if(cardBill.billType == CardBillType.IN){
		params.queryName = "card_warehousing_bill";
	}else if(cardBill.billType == CardBillType.OUT){
	params.queryName = "card_delivery_bill";
	}else if(cardBill.billType == CardBillType.ADJUST){
		params.queryName = "card_adjustment_bill";
	}
	return params;
}
function printBill(cardBill){
	var params = getBillParams(cardBill)
	Eui.getBillHtml('content',params)
}

function exportBillToPdf(){
	var params = getBillParams()
	params.exportType = "pdf"
	Eui.exportBill(params);
}

CardStore.getStoreStatus = function(){
	return  Common.getSubsetItems(CardStatus.CATEGORY, [CardStatus.INITED, CardStatus.OK, CardStatus.REVOCATION]);
}
CardStore.formatStatDate = function (){
		var form = Page.form;
		if (!form) return;
		var statType = Common.getRadioValue("statType");
	
		if(statType == Constants.CLEAR_STAT_DYNA){
			if(!checkTimeOrder(form.beginDate,form.endDate))
			return false;
		}else if(statType == Constants.CLEAR_STAT_DAY ){
			var sDate = form.statDate.value;
			form.beginDate.value = Format.getBeginTimeOfDay(sDate);
			form.endDate.value = Format.getEndTimeOfDay(sDate);
			
		}else if(statType == Constants.CLEAR_STAT_MONTH){
			var sDate = form.statDate.value;
			form.beginDate.value = Format.getBeginTimeOfMonth(sDate);
			form.endDate.value = Format.getEndTimeOfMonth(sDate);
			 
		}else if(statType == Constants.CLEAR_STAT_YEAR){
			var sDate = form.statDate.value;
			form.beginDate.value = Format.getBeginTimeOfYear(sDate);
			form.endDate.value = Format.getEndTimeOfYear(sDate);
		}
		return true;
}
CardStore.statDateType = function (){
		var form = Page.form;
		if (!form) return;
		var statType = Common.getRadioValue("statType");
	
		if(statType == Constants.CLEAR_STAT_DYNA){
			$("beginDateTD").style.display=''
			$("endDateTD").style.display=''
			$("statDateTD").style.display='none'
			form.beginDate.value = TX.Misc.getDateBefore(1);
			form.endDate.value = TX.Misc.getDateBefore(1);
		
			return false;
		}else if(statType == Constants.CLEAR_STAT_DAY ){
			form.statDate.value = TX.Misc.getDateBefore(1);
			
			$("beginDateTD").style.display='none'
			$("endDateTD").style.display='none'
			$("statDateTD").style.display=''
		
		}else if(statType == Constants.CLEAR_STAT_MONTH){
			form.statDate.value = TX.Misc.getDateBefore(1);
			 $("beginDateTD").style.display='none'
			 $("endDateTD").style.display='none'
			  $("statDateTD").style.display=''
			
		}else if(statType == Constants.CLEAR_STAT_YEAR){
			form.statDate.value = TX.Misc.getDateBefore(1);
			 $("beginDateTD").style.display='none'
			 $("endDateTD").style.display='none'
			 $("statDateTD").style.display=''
		}
		return true;
}
var Page = {};
CardStore.initCardStoreStat = function(divid){
	Rpc.loadPage(divid,"/store/cardstore_stat_div.html",function(){
		Page.form = $("statForm");
		
		Eui.initBeginDateInput("beginDateTd","起始日期","statForm","beginDate","endDate","_pastDate",true);
		Eui.initEndDateInput("endDateTd","结束日期","statForm","beginDate","endDate","_pastDate",true);
		Eui.initDateInput("statDateTd","统计日期","statForm","statDate","_pastDate",true)
		CardStore.statDateType()
		});
}
